import type { MaybeRefOrGetter } from 'vue'
import { TIDS } from './types'
import WrapComponent from './components/WrapComponent.vue'
import OrganizationalBlockDiagram from './components/OrganizationalBlockDiagram.vue'

import PersonnelList from './components/PersonnelList.vue'
import ListOfMajorEnergyUsingEquipment from './components/ListOfMajorEnergyUsingEquipment.vue'

import ListOfMeasuringInstruments from './components/ListOfMeasuringInstruments.vue'
import EntryAndExitOfMajorSecondaryUnitEnergyMeteringInstruments from './components/EntryAndExitOfMajorSecondaryUnitEnergyMeteringInstruments.vue'
import ListOfEnergyMeasuringInstrumentsForUnitEnergyUseInAndOut from './components/ListOfEnergyMeasuringInstrumentsForUnitEnergyUseInAndOut.vue'
import ListOfEnergyMeasuringInstrumentsForMajorEnergyUsingEquipment from './components/ListOfEnergyMeasuringInstrumentsForMajorEnergyUsingEquipment.vue'
import ListOfOtherEnergyMeasuringInstruments from './components/ListOfOtherEnergyMeasuringInstruments.vue'

import StatisticalSummaryOfEnergyMeteringEquipment from './components/StatisticalSummaryOfEnergyMeteringEquipment/StatisticalSummaryOfEnergyMeteringEquipment.vue'
import StatisticalSummaryOfAccuracyGradesOfEnergyMeteringInstruments from './components/StatisticalSummaryOfAccuracyGradesOfEnergyMeteringInstruments.vue'
import AnnualEnergyPurchases from './components/AnnualEnergyPurchases.vue'

import EnergyFlowDiagram from './components/EnergyFlowDiagram.vue'
import MeteringCollectionPointNetworkDiagram from './components/MeteringCollectionPointNetworkDiagram.vue'
import SelfVerificationOfEnergyMeasuringInstruments from './components/SelfVerificationOfEnergyMeasuringInstruments.vue'
import EnergyMeasuringInstrumentsQuantityValueTransfer from './components/EnergyMeasuringInstrumentsQuantityValueTransfer.vue'

export type ReportComponent =
  | typeof WrapComponent
  | typeof OrganizationalBlockDiagram
  | typeof PersonnelList
  | typeof ListOfMajorEnergyUsingEquipment
  | typeof ListOfMeasuringInstruments
  | typeof EntryAndExitOfMajorSecondaryUnitEnergyMeteringInstruments
  | typeof ListOfEnergyMeasuringInstrumentsForUnitEnergyUseInAndOut
  | typeof ListOfEnergyMeasuringInstrumentsForMajorEnergyUsingEquipment
  | typeof ListOfOtherEnergyMeasuringInstruments
  | typeof StatisticalSummaryOfEnergyMeteringEquipment
  | typeof StatisticalSummaryOfAccuracyGradesOfEnergyMeteringInstruments
  | typeof AnnualEnergyPurchases
  | typeof EnergyFlowDiagram
  | typeof MeteringCollectionPointNetworkDiagram
  | typeof SelfVerificationOfEnergyMeasuringInstruments
  | typeof EnergyMeasuringInstrumentsQuantityValueTransfer

export interface CurrentReportStatus {
  /** 表ID */
  tId: number
  /** 是否查看操作 */
  isView: boolean
  /** 是否编辑操作 */
  isEdit: boolean
}

function useReportComponent(option: MaybeRefOrGetter<CurrentReportStatus>) {
  const component = shallowRef<ReportComponent>(WrapComponent)

  function updateComponent() {
    component.value = WrapComponent

    const { tId, isView, isEdit } = toValue(option)

    if (isView) {
      switch (tId) {
        case TIDS.ORGANIZATIONAL_BLOCK_DIAGRAM:
          component.value = OrganizationalBlockDiagram
          break
        case TIDS.PERSONNEL_LIST:
          component.value = PersonnelList
          break
        case TIDS.LIST_OF_MAJOR_ENERGY_USING_EQUIPMENT:
          component.value = ListOfMajorEnergyUsingEquipment
          break
        case TIDS.LIST_OF_MEASURING_INSTRUMENTS:
          component.value = ListOfMeasuringInstruments
          break
        case TIDS.LIST_OF_ENERGY_MEASURING_INSTRUMENTS_FOR_UNIT_ENERGY_USE_IN_AND_OUT:
          component.value = ListOfEnergyMeasuringInstrumentsForUnitEnergyUseInAndOut
          break
        case TIDS.ENTRY_AND_EXIT_OF_MAJOR_SECONDARY_UNIT_ENERGY_METERING_INSTRUMENTS:
          component.value = EntryAndExitOfMajorSecondaryUnitEnergyMeteringInstruments
          break
        case TIDS.LIST_OF_ENERGY_MEASURING_INSTRUMENTS_FOR_MAJOR_ENERGY_USING_EQUIPMENT:
          component.value = ListOfEnergyMeasuringInstrumentsForMajorEnergyUsingEquipment
          break
        case TIDS.LIST_OF_OTHER_ENERGY_MEASURING_INSTRUMENTS:
          component.value = ListOfOtherEnergyMeasuringInstruments
          break
        case TIDS.STATISTICAL_SUMMARY_OF_ENERGY_METERING_EQUIPMENT:
          component.value = StatisticalSummaryOfEnergyMeteringEquipment
          break
        case TIDS.STATISTICAL_SUMMARY_OF_ACCURACY_GRADES_OF_ENERGY_METERING_INSTRUMENTS:
          component.value = StatisticalSummaryOfAccuracyGradesOfEnergyMeteringInstruments
          break
        case TIDS.ANNUAL_ENERGY_PURCHASES:
          component.value = AnnualEnergyPurchases
          break
        case TIDS.ENERGY_FLOW_DIAGRAM:
          component.value = EnergyFlowDiagram
          break
        case TIDS.METERING_COLLECTION_POINT_NETWORK_DIAGRAM:
          component.value = MeteringCollectionPointNetworkDiagram
          break
        case TIDS.SELF_VERIFICATION_OF_ENERGY_MEASURING_INSTRUMENTS:
          component.value = SelfVerificationOfEnergyMeasuringInstruments
          break
        case TIDS.ENERGY_MEASURING_INSTRUMENTS_QUANTITY_VALUE_TRANSFER:
          component.value = EnergyMeasuringInstrumentsQuantityValueTransfer
          break
      }
    }
    else if (isEdit) {
      switch (tId) {
        case TIDS.PERSONNEL_LIST:
          component.value = PersonnelList
          break
        case TIDS.LIST_OF_MAJOR_ENERGY_USING_EQUIPMENT:
          component.value = ListOfMajorEnergyUsingEquipment
          break
        case TIDS.LIST_OF_MEASURING_INSTRUMENTS:
          component.value = ListOfMeasuringInstruments
          break
        case TIDS.LIST_OF_ENERGY_MEASURING_INSTRUMENTS_FOR_UNIT_ENERGY_USE_IN_AND_OUT:
          component.value = ListOfEnergyMeasuringInstrumentsForUnitEnergyUseInAndOut
          break
        case TIDS.ENTRY_AND_EXIT_OF_MAJOR_SECONDARY_UNIT_ENERGY_METERING_INSTRUMENTS:
          component.value = EntryAndExitOfMajorSecondaryUnitEnergyMeteringInstruments
          break
        case TIDS.LIST_OF_ENERGY_MEASURING_INSTRUMENTS_FOR_MAJOR_ENERGY_USING_EQUIPMENT:
          component.value = ListOfEnergyMeasuringInstrumentsForMajorEnergyUsingEquipment
          break
        case TIDS.LIST_OF_OTHER_ENERGY_MEASURING_INSTRUMENTS:
          component.value = ListOfOtherEnergyMeasuringInstruments
          break
        case TIDS.STATISTICAL_SUMMARY_OF_ENERGY_METERING_EQUIPMENT:
          component.value = StatisticalSummaryOfEnergyMeteringEquipment
          break
        case TIDS.STATISTICAL_SUMMARY_OF_ACCURACY_GRADES_OF_ENERGY_METERING_INSTRUMENTS:
          component.value = StatisticalSummaryOfAccuracyGradesOfEnergyMeteringInstruments
          break
        case TIDS.ANNUAL_ENERGY_PURCHASES:
          component.value = AnnualEnergyPurchases
          break
      }
    }
  }

  watchEffect(() => {
    updateComponent()
  })

  return {
    component,
  }
}

export default useReportComponent
